import svcInvoke from "../svcinvoke";
export default {
	namespaced: true,
	state:{
		select:{},/* 点击选中的股票 */
		symbol:{},/* 全部行情外层 */
		symbos:{},/* 当前页面显示行情 */
		ticket:{},/* 动态行情 */
		optionlist:[],/* 全部行情 */
	},
	mutations:{
		select(state, code){
      // console.log(code,'code');
      state.select = code;
		},
		setSymbol(state, payload) {
			let symbol = new Object(),symbols = Object.assign(new Array(),state.symbos);
			for(var key in payload) {
				if( payload[key]['title'] ){
					symbol[ payload[key]['title'] ] = payload[key];
				}
			}
      for(var key in payload) {
      	if( payload[key]['title'] ){
      		symbol[ payload[key]['title'] ] = payload[key];
      		if( !symbols[ payload[key]['title'] ] ){
              symbols.push(payload[key]);
      		}
          if( !state.select.code ){
          	let select   = Object.assign(new Object(),payload[key].symbols);
            for(var selectli in select){
              state.select = select[selectli];
              break;
            }
            break;
          }
      	}
      }
			state.symbol  = symbol;
			state.symbos  = symbols;
		},
    setSymbos(state, payload) {
    	let symbols = Object.assign(new Array(),payload);
      state.symbos  = symbols;
    },
		delSymbol(state, key) {
			if( state.symbol[key] ){
				delete state.symbol[key]
			}
		},
    setTicket(state, symbol) {
    	let ticket = Object.assign({},state.ticket);
    	if( symbol.symbol ){
    		ticket[symbol.code2] = symbol;
    	}else if(symbol.code2){
    		symbol.symbol = symbol.code2;
    		ticket[symbol.symbol] = symbol;
    	}
    	state.ticket = ticket;
    },
		setOptionlist(state, symbol) {
      // console.log(symbol);
      //let optionlsit = new Array();
      let optionlsit = {};
      for(let i=0;i<symbol.length;i++){
        for(let j=0;j<symbol[i].symbols.length;j++){
          optionlsit[symbol[i].symbols[j]['code']] = symbol[i].symbols[j]
          //optionlsit.push(symbol[i].symbols[j])
        }
      }
      // console.log(optionlsit);
			state.optionlist = optionlsit;
		},
		delTicekt(state, code) {
			if( state.ticket[code] ){
				delete state.ticket[code]
			}
		}
	},
	actions:{
		// order_position ({ commit, state }, params) {
		// 	svcInvoke.get('addons/tf-futures/order/list?state=hold',params||{}).then(res=>{
		// 		if( res.code==200 ){
		// 			state.order_position = res.data
		// 		}
		// 	})
		// }
	}
}
